package au.com.twosquared.animalfarm.ui;

import java.awt.Rectangle;
import java.util.ArrayList;

import au.com.twosquared.animalfarm.ui.components.Component;

@SuppressWarnings("serial")
public class UIManager extends ArrayList<Component> {
	/**
	 * Checks if a touch made is on a component
	 * 
	 * @param x the x coordinate of point touched
	 * @param y the y coordinate of point touched
	 */
	public void touch(int x, int y) {
		for (Component c : this) {
			int cx = (int) c.x;
			int cy = (int) c.y;
			int cw = (int) c.width;
			int ch = (int) c.height;
			Rectangle rect1 = new Rectangle(cx+cw, cy+ch, cw, ch);
			Rectangle rect2 = new Rectangle(x-10, y-10, 20, 20); 
			if (rect1.intersects(rect2)) {
				c.trigger();

			}
		}
	}

	public void focus(Component c) {
		for (Component co : this) {
			if (co.equals(c)) {
				c.focus = true;
			} else {
				co.focus = false;
			}
		}
	}

	public void draw() {
		// Draw all my components
	}

}
